﻿<UserControl x:Class="Anagramme.Views.LobbyView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:conv="clr-namespace:Anagramme.Converters;assembly=Anagramme.Common"
             mc:Ignorable="d"
             d:DataContext="{d:DesignData Source=/SampleData/LobbyViewModelSampleData.xaml}"
             d:DesignHeight="700" d:DesignWidth="400">
    <UserControl.Resources>
        <conv:ListItemIndexConverter x:Key="ListItemIndexConverter" />
    </UserControl.Resources>
    <Grid DataContext="{Binding}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <StackPanel Margin="12,12,12,0" VerticalAlignment="Top" >
            <StackPanel Orientation="Horizontal">
                <Button Style="{DynamicResource ResourceKey=BackButton}" 
                        Command="{Binding Path=GoBackCommand, Mode=OneTime}" />
                <TextBlock Margin="5,0,0,0" VerticalAlignment="Center"
                           Text="{Binding Path=Lobby.TITLE, Source={StaticResource ResourceKey=Resources}}" Style="{DynamicResource Titre}" />
            </StackPanel>
            <Grid  Margin="0,24,0,0" VerticalAlignment="Top" >
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <ListBox Grid.ColumnSpan="2" Background="Transparent" BorderThickness="0" HorizontalContentAlignment="Stretch"
                         AlternationCount="{Binding Path=Players.Count}" Padding="0"
                         ItemsSource="{Binding Path=Players}" >
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Grid Margin="0,5,0,0" >
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" SharedSizeGroup="col1" />
                                    <ColumnDefinition Width="*" SharedSizeGroup="col2" />
                                    <ColumnDefinition Width="Auto" SharedSizeGroup="col3" />
                                </Grid.ColumnDefinitions>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding Path=Lobby.PLAYER, StringFormat='{}{0} ', Source={StaticResource ResourceKey=Resources}}"
                                               Style="{DynamicResource SousTitre}" VerticalAlignment="Center" />
                                    <TextBlock Text="{Binding Path=TemplatedParent.(ItemsControl.AlternationIndex), Converter={StaticResource ResourceKey=ListItemIndexConverter}, RelativeSource={RelativeSource TemplatedParent}}" 
                                               Style="{DynamicResource SousTitre}" VerticalAlignment="Center" />
                                </StackPanel>
                                <TextBlock Grid.Column="1" Margin="12,0,5,0" 
                                           Text="{Binding Path=Name, Mode=OneWay}" 
                                           Style="{DynamicResource Texte}" VerticalAlignment="Center" />
                                <Image Grid.Column="2" 
                                       Source="/Anagramme.Common;component/Images/is_ready_to_play.png"
                                       Visibility="{Binding Path=IsReadyToPlay, Mode=OneWay, Converter={StaticResource ResourceKey=BooleanToVisibilityConverter}, ConverterParameter=True}" />
                            </Grid>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
                <TextBlock Grid.Row="1" Margin="0,24,12,0"
                           Text="{Binding Path=Lobby.IP, Source={StaticResource ResourceKey=Resources}}" 
                           Visibility="{Binding Path=Player.IsLobbyMaster, Mode=OneWay, Converter={StaticResource ResourceKey=BooleanToVisibilityConverter}}"
                           Style="{DynamicResource ResourceKey=SousTitre}" />
                <TextBlock Grid.Row="1" Grid.Column="1" Margin="0,24,0,0" VerticalAlignment="Center"
                           Visibility="{Binding Path=Player.IsLobbyMaster, Mode=OneWay, Converter={StaticResource ResourceKey=BooleanToVisibilityConverter}}"
                           Style="{DynamicResource TexteImportant}" 
                           Text="{Binding Path=ServerIP}" />
                <TextBlock Grid.Column="1" Grid.Row="2" Margin="0,6,0,0"
                           Text="{Binding Path=Lobby.IPINFO, Source={StaticResource ResourceKey=Resources}}" 
                           Visibility="{Binding Path=Player.IsLobbyMaster, Mode=OneWay, Converter={StaticResource ResourceKey=BooleanToVisibilityConverter}}"
                           VerticalAlignment="Center" TextWrapping="Wrap" Style="{DynamicResource ResourceKey=Texte}" />
            </Grid>
        </StackPanel>
        <StackPanel Margin="12,72,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="235" Grid.Row="1">
            <TextBlock Style="{DynamicResource SousTitre}"
                       Text="{Binding Path=Lobby.SCOREOPTIONS, Source={StaticResource ResourceKey=Resources}}" />
            <Grid Margin="0,5,0,0" >
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <RadioButton Name="roundModeRadio" Style="{DynamicResource ResourceKey=RadioButton}"
                             Content="{Binding Path=Lobby.ROUNDGAMEMODE, Source={StaticResource ResourceKey=Resources}}" 
                             IsChecked="{Binding Infos.GameMode, ConverterParameter=False, Converter={StaticResource GameModesToBooleanConverter}, Mode=TwoWay}"
                             IsEnabled="{Binding Path=Player.IsLobbyMaster, Mode=OneWay}"
                             VerticalAlignment="Center" />
                <TextBox Margin="5,0,0,0" Width="70" Grid.Column="1" Style="{DynamicResource TextBox}"
                         Text="{Binding Infos.TargetRounds, UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True, ValidatesOnDataErrors=True, ValidatesOnExceptions=True}"
                         Visibility="{Binding Path=IsChecked, Mode=OneWay, ElementName=roundModeRadio, Converter={StaticResource ResourceKey=BooleanToVisibilityConverter}, ConverterParameter=True}"
                         IsEnabled="{Binding Path=Player.IsLobbyMaster, Mode=OneWay}" />
                <RadioButton Name="scoreModeRadio" Style="{DynamicResource ResourceKey=RadioButton}" 
                             Content="{Binding Path=Lobby.SCOREGAMEMODE, Source={StaticResource ResourceKey=Resources}}"
                             IsChecked="{Binding Infos.GameMode, ConverterParameter=True, Converter={StaticResource GameModesToBooleanConverter}, Mode=TwoWay}"
                             IsEnabled="{Binding Path=Player.IsLobbyMaster, Mode=OneWay}"
                             Margin="0,5,0,0" Grid.Row="1" VerticalAlignment="Center" />
                <TextBox Margin="5,5,0,0" Width="70" Grid.Row="1" Grid.Column="1" Style="{DynamicResource TextBox}"
                         Text="{Binding Infos.TargetScore, UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True, ValidatesOnDataErrors=True, ValidatesOnExceptions=True}"
                         Visibility="{Binding Path=IsChecked, Mode=OneWay, ElementName=scoreModeRadio, Converter={StaticResource ResourceKey=BooleanToVisibilityConverter}, ConverterParameter=True}"
                         IsEnabled="{Binding Path=Player.IsLobbyMaster, Mode=OneWay}" />
            </Grid>
            <TextBlock Margin="0,12,0,0" Style="{DynamicResource SousTitre}"
                       Text="{Binding Path=Lobby.WORDSOPTIONS, Source={StaticResource ResourceKey=Resources}}" />
            <Grid Margin="0,5,0,0" >
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <TextBlock Margin="0,0,0,0" VerticalAlignment="Center" Style="{DynamicResource Texte}"
                           Text="{Binding Path=Lobby.MINWORDS, Source={StaticResource ResourceKey=Resources}}" />
                <TextBox Margin="5,0,0,0" Width="70" Grid.Column="1" Style="{DynamicResource TextBox}"
                         IsEnabled="{Binding Path=Player.IsLobbyMaster, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
                         Text="{Binding Infos.MinWordsLength, UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True, ValidatesOnDataErrors=True, ValidatesOnExceptions=True}"/>
                <TextBlock Margin="0,5,0,0" Grid.Row="1" VerticalAlignment="Center" Style="{DynamicResource Texte}"
                           Text="{Binding Path=Lobby.MAXWORDS, Source={StaticResource ResourceKey=Resources}}" />
                <TextBox Margin="5,5,0,0" Width="70" Grid.Row="1" Grid.Column="1" Style="{DynamicResource TextBox}"
                         IsEnabled="{Binding Path=Player.IsLobbyMaster, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
                         Text="{Binding Infos.MaxWordsLength, UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True, ValidatesOnDataErrors=True, ValidatesOnExceptions=True}"/>
            </Grid>
        </StackPanel>
        <StackPanel Margin="0,0,12,12" HorizontalAlignment="Right" VerticalAlignment="Bottom" Orientation="Horizontal" Grid.Row="1">
            <Image Grid.Column="2" Grid.Row="1" Margin="0,0,0,0" Width="20" VerticalAlignment="Center"
                   Source="/Anagramme.Common;component/Images/is_ready_to_play.png" Stretch="Uniform"
                   Visibility="{Binding Path=IsReady, Mode=OneWay, Converter={StaticResource ResourceKey=BooleanToVisibilityConverter}, ConverterParameter=True}" />
            <ToggleButton Content="{Binding Path=Lobby.ISREADY, Source={StaticResource ResourceKey=Resources}}" Margin="2,0,0,0"
                          Command="{Binding Path=ReadyToPlayCommand, Mode=OneTime}"
                          IsChecked="{Binding Path=IsReady, Mode=TwoWay}" Style="{DynamicResource ToggleButton}" />
            <Button Margin="5,0,0,0"
                    Content="{Binding Path=Lobby.START, Source={StaticResource ResourceKey=Resources}}"
                    Visibility="{Binding Path=Player.IsLobbyMaster, Mode=OneWay, Converter={StaticResource ResourceKey=BooleanToVisibilityConverter}}"
                    Command="{Binding Path=StartCommand, Mode=OneTime}" Style="{DynamicResource Button}" />
        </StackPanel>
    </Grid>
</UserControl>
